package gui.card;

import gui.alert;
import pojo.Card;
import service.cardService;

import javax.swing.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

public class card_sell_window {
    private JPanel sell_card_panal;
    private JTabbedPane tabbedPane1;
    private JTextField discount_rate;
    private JTextField username;
    private JTextField tel;
    private JTextField user_id_Card;
    private JButton 确认办卡Button;
    private JTextField c_rate;
    private JTextField c_money;
    private JTextField c_name;
    private JTextField c_tel;
    private JTextField c_id_;
    private JButton c_confirm_add_card_Button1;

    public card_sell_window() {
        //会员卡办理
        确认办卡Button.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                Card c = new Card();
                c.setIdCard(user_id_Card.getText());
                c.setDiscountRate(Double.parseDouble(discount_rate.getText()));
                c.setTel(tel.getText());
                c.setType("会员卡");
                c.setUsername(username.getText());
                if (cardService.insert(c) == 1) {
                    alert.show("办卡成功");
                } else {
                    alert.show("办卡失败");
                }
            }
        });
        //储蓄卡办理
        c_confirm_add_card_Button1.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                super.mouseClicked(e);
                Card c = new Card();
                c.setUsername(c_name.getText());
                c.setIdCard(c_id_.getText());
                c.setDiscountRate(Double.parseDouble(c_rate.getText()));
                c.setMoney(Double.parseDouble(c_money.getText()));
                c.setType("储蓄卡");
                c.setTel(c_tel.getText());
                if (cardService.insert(c) == 1) {
                    alert.show("办卡成功");
                } else {
                    alert.show("办卡失败");
                }
            }
        });
    }

    public static void show() {
        JFrame frame = new JFrame("售卡");
        frame.setContentPane(new card_sell_window().sell_card_panal);
        frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }
}
